<?php


namespace app\common\helper;

class Time
{
	public static function timeData() : array
	{
		list($start_t, $end_t) = \think\helper\Time::today();
		$start_today = date("Y-m-d H:i:s", $start_t);
		$end_today = date("Y-m-d H:i:s", $end_t);
		list($start_zt, $end_zt) = \think\helper\Time::yesterday();
		$start_yesterday = date("Y-m-d H:i:s", $start_zt);
		$end_yesterday = date("Y-m-d H:i:s", $end_zt);
		list($start_s, $end_s) = \think\helper\Time::dayToNow(7);
		$start_seven = date("Y-m-d H:i:s", $start_s);
		$end_seven = date("Y-m-d H:i:s", $end_s);
		list($start_f, $end_f) = \think\helper\Time::dayToNow(15);
		$start_fifteen = date("Y-m-d H:i:s", $start_f);
		$end_fifteen = date("Y-m-d H:i:s", $end_f);
		return ["start_t" => $start_t, "end_t" => $end_t, "start_zt" => $start_zt, "end_zt" => $end_zt, "start_s" => $start_s, "end_s" => $end_s, "start_f" => $start_f, "end_f" => $end_f, "start_today" => $start_today, "end_today" => $end_today, "start_yesterday" => $start_yesterday, "end_yesterday" => $end_yesterday, "start_seven" => $start_seven, "end_seven" => $end_seven, "start_fifteen" => $start_fifteen, "end_fifteen" => $end_fifteen];
	}
	public static function get_month_dates($time = "", $format = "Y-m-d") : array
	{
		$time = $time ?: time();
		$day = date("d", $time);
		$date = [];
		for ($i = 1; $i <= date("t"); $i++) {
			$date[] = date($format, strtotime("+" . ($i - $day) . " days", $time));
		}
		return $date;
	}
	public static function get_week_dates($time = "", $format = "Y-m-d") : array
	{
		$time = $time ?: time();
		$week = date("w", $time);
		$date = [];
		for ($i = 1; $i <= 7; $i++) {
			$date[] = date($format, strtotime("+" . ($i - $week) . " days", $time));
		}
		return $date;
	}
	public static function computing_time($type, $value, $time)
	{
		file_put_contents("a", $type . $value);
		if (!$time || $time < time()) {
			$date = date("Y-m-d H:i:s");
		} else {
			$date = date("Y-m-d H:i:s", $time);
		}
		$type = \intval($type);
		$value = \intval($value);
		if ($type == 0) {
			$time = strtotime($date . " + {$value} minute");
		} elseif ($type == 1) {
			$time = strtotime($date . " + {$value} hour");
		} elseif ($type == 2) {
			$time = strtotime($date . " + {$value} day");
		} elseif ($type == 3) {
			$time = strtotime($date . " + {$value} week");
		} elseif ($type == 4) {
			$time = strtotime($date . " + {$value} month");
		} elseif ($type == 7) {
			$time = strtotime($date . " + " . $value * 3 . " month");
		} elseif ($type == 8) {
			$time = strtotime($date . " + " . $value * 6 . " month");
		} elseif ($type == 5) {
			$time = strtotime($date . " + {$value} year");
		} elseif ($type == 6) {
			$time = \app\common\model\DefaultConfig::PerpetualTimeValue;
		} else {
			$time = 0;
		}
		return $time;
	}
	public static function get_cycle_time($type) : array
	{
		if ($type == 1) {
			$time_start = mktime(date("H"), 0, 0, date("m"), date("d"), date("Y"));
			$time_end = mktime(date("H"), 59, 59, date("m"), date("d"), date("Y"));
		} elseif ($type == 2) {
			list($time_start, $time_end) = \think\helper\Time::today();
		} elseif ($type == 3) {
			list($time_start, $time_end) = \think\helper\Time::week();
		} elseif ($type == 4) {
			list($time_start, $time_end) = \think\helper\Time::month();
		} elseif ($type == 5) {
			list($time_start, $time_end) = \think\helper\Time::year();
		} elseif ($type == 6) {
			list($time_start, $time_end) = [0, time()];
		} else {
			list($time_start, $time_end) = [0, 0];
		}
		return [$time_start, $time_end];
	}
}